//
//  GoodsDetailController.m
//  WuJieLive
//
//  Created by iMac on 2017/11/15.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "GoodsDetailController.h"
#import "TitleSegementView.h"
#import "ProductionView.h"
#import "CommentModel.h"
#import "GoodsModel.h"
#import "SpecificationModel.h"
#import "DetailGoodsModel.h"
#import "OrderDetailModel.h"
#import "OrderTicketModel.h"
#import "CartViewController.h"
#import "GoodsCommentController.h"
#import "ConfirmOrderController.h"
#import "SpecificationView.h"
#import "CommentsCell.h"
#import "BottomTool.h"

@interface GoodsDetailController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>

// 头部滑动是titleSegementView btn点击事件用block回传
// 整体设计是 tableview + tableHeaderView

@property (nonatomic , strong) TitleSegementView * titleSegementView;
@property (nonatomic , strong) UITableView * tableview;
@property (nonatomic , strong) UIView * headerView;

@property (nonatomic , strong) UILabel * titleLabel; // 名称
@property (nonatomic , strong) UILabel * priceLable; // 价格
@property (nonatomic , strong) UILabel * stockLabel; // 库存
@property (nonatomic , strong) UILabel * pastPriceLabel; // 原来的价格
@property (nonatomic , strong) NSString * fareMoney; // 运费
@property (nonatomic , strong) NSString * commentCountString; // 评论个数（要显示的字符串）
@property (nonatomic , assign) NSInteger comentCount; // 评论个数
@property (nonatomic , strong) NSArray * picturesArray; // 轮播图数据源
@property (nonatomic , strong) SDCycleScrollView * header; // 轮播图
@property (nonatomic , strong) NSMutableArray * commentsArray;  // 评论数组
@property (nonatomic , strong) NSDictionary * fareInfo;  // 运费信息
@property (nonatomic , strong) NSMutableArray * modelArray;  // 装model的数组
@property (nonatomic , strong) NSMutableArray * detailArray; // 小model
@property (nonatomic , strong) GoodsModel * dataModel; // 装有规格信息的model
@property (nonatomic , assign) NSInteger specDeep; // 规格个数
@property (nonatomic , assign) BOOL isColloection;

@property (nonatomic , strong) UIButton * scoreBtn;
@property (nonatomic , strong) UIButton * rebackBtn;

@property (nonatomic , strong) BottomTool * tool;
@property (nonatomic , strong) ProductionView * productionView;
@property (nonatomic , strong) SpecificationView * specView;

@end

@implementation GoodsDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)setNavi
{
    self.navigationItem.titleView = self.titleSegementView = [[TitleSegementView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth * 0.58, 35) andtitleArray:@[@"商品",@"评价",@"详情"]];
    __weak typeof(self) weakSelf = self;
    self.titleSegementView.selectedBlock = ^(NSInteger index) {
        if (index == 0) {
            [weakSelf.tableview setContentOffset:CGPointZero animated:YES];
        }else if (index == 1){
            [weakSelf.tableview setContentOffset:CGPointMake(0, 635) animated:YES];
        }else
        {
            NSIndexPath * path = [NSIndexPath indexPathForRow:0 inSection:3];
            [weakSelf.tableview scrollToRowAtIndexPath:path atScrollPosition:(UITableViewScrollPositionTop) animated:YES];
        }
    };
    
    UIButton * btnMore = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btnMore.frame = CGRectMake(0, 0, 30, 30);
    btnMore.backgroundColor = [UIColor clearColor];
    btnMore.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -20);
    btnMore.titleLabel.font = FontSize(15);
    [btnMore setTitleColor:TextAssistColor forState:(UIControlStateNormal)];
    [btnMore addTarget:self action:@selector(moreAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [btnMore setImage:Image(@"icon_nav_更多") forState:(UIControlStateNormal)];
    UIBarButtonItem * btn1 = [[UIBarButtonItem alloc]initWithCustomView:btnMore];
    
    UIButton * btnShare = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btnShare.frame = CGRectMake(0, 0, 30, 30);
    btnShare.backgroundColor = [UIColor clearColor];
    btnMore.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -20);
    btnShare.titleLabel.font = FontSize(15);
    [btnShare setTitleColor:TextAssistColor forState:(UIControlStateNormal)];
    [btnShare addTarget:self action:@selector(shareAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [btnShare setImage:Image(@"icon_nav_分享") forState:(UIControlStateNormal)];
    UIBarButtonItem * btn2 = [[UIBarButtonItem alloc]initWithCustomView:btnShare];
    
    self.navigationItem.rightBarButtonItems = @[btn1,btn2];
}

-(void)setUI
{
    self.view.backgroundColor = Color(245, 245, 245);
    self.headerView.frame = CGRectMake(0, 0, kScreenWidth, 475);
    self.header = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 375) delegate:self placeholderImage:Image(@"")];
    [self.headerView addSubview:self.header];
    UIView * headerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.header.frame), kScreenWidth, 100)];
    [self.headerView addSubview:headerBgView];

    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.numberOfLines = 2;
    self.titleLabel.textColor = TextAssistColor;
    self.titleLabel.font = FontSize(15);
    [headerBgView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.top.offset(10);
    }];
    
    self.priceLable = [[UILabel alloc]init];
    [headerBgView addSubview:self.priceLable];
    [self.priceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
    }];
    self.priceLable.font = FontSize(24);
    self.priceLable.textColor = MainColor;
    
    self.pastPriceLabel = [[UILabel alloc]init];
    [headerBgView addSubview:self.pastPriceLabel];
    [self.pastPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.priceLable);
        make.left.equalTo(self.priceLable.mas_right).offset(10);
    }];
    
    self.stockLabel = [[UILabel alloc]init];
    [headerBgView addSubview:self.stockLabel];
    self.stockLabel.font = FontSize(12);
    self.stockLabel.textColor = TextAssistColor;
    [headerBgView addSubview:self.stockLabel];
    self.stockLabel.numberOfLines = 0;
    [self.stockLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.centerY.equalTo(self.priceLable);
    }];
    
    self.tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 110) style:(UITableViewStyleGrouped)];
    self.tableview.tableHeaderView = self.headerView;
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    [self.tableview registerNib:[UINib nibWithNibName:@"CommentsCell" bundle:nil] forCellReuseIdentifier:@"CommentsCell"];
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"BtnCell"];
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"webCell"];
    [self.view addSubview:self.tableview];
    
    [self.view addSubview:self.tool];
    [self.tool mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.height.offset(50);
    }];
    __weak typeof(self) weakSelf = self;
    self.tool.buyNowBlock = ^{   // 立即购买
        [weakSelf buyNow];
    };
    self.tool.collectBlock = ^{   // 收藏
        [weakSelf collectionGoods];
    };
    self.tool.takeInCartBlock = ^{  // 加入购物车
        [weakSelf takeInCart];
    };
    self.tool.cartBlock = ^{     //  与收藏并列的购物车的按钮  跳转购物车
        CartViewController * vc = [[CartViewController alloc]init];
        vc.needLeftBtn = YES;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
    [MBProgressHUD showHUDAddedTo:self.tableview animated:YES];
}

- (void)buyNow
{
    
}

- (void)takeInCart
{
    
}

- (void)collectionGoods
{
    if (self.isLogin) {
        if (self.isColloection) {

        }else
        {
            [MBProgressHUD showHUDAddedTo:self.tableview animated:YES];
            NSDictionary * dict = @{@"token":self.userToken,@"goods_id":self.goodsID};
            [HTTPTool POSTForm:[NSString stringWithFormat:@"%@user-collection/add-to-collection",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
                [MBProgressHUD hideHUDForView:self.tableview animated:YES];
                if (isSuccess) {
                    self.isColloection = self.tool.collectionBtn.selected = YES;
                }
            } failure:^(NSError *error) {
                [MBProgressHUD hideHUDForView:self.tableview animated:YES];
            }];
        }
        
    }else
    {
        
    }
}

-(void)getGoodsDetail
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary * dict = @{@"goods_id":self.goodsID};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@goods/goods-detail-intro",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

-(void)setData
{
    NSDictionary * dict = @{@"goods_id":self.goodsID};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@goods/goods-detail",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.tableview animated:YES];
        if (isSuccess) {
//            [self getGoodsDetail];
            self.specDeep = [responseObject[@"data"][@"spec_deep"] integerValue];
            [self.dataModel setValuesForKeysWithDictionary:responseObject[@"data"][@"spec_info"]];
            self.modelArray = [NSMutableArray array];
            self.detailArray = [NSMutableArray array];
            for (int i = 0; i < self.dataModel.spec_list.count; i ++) {
                SpecificationModel * model = [SpecificationModel new];
                [model setValuesForKeysWithDictionary:self.dataModel.spec_list[i]];
                model.selectedIndex = -1;
                [self.modelArray addObject:model];
            }
            for (int i = 0 ; i < self.dataModel.spec_contents.count; i ++) {
                DetailGoodsModel * model = [[DetailGoodsModel alloc]init];
                [model setValuesForKeysWithDictionary:self.dataModel.spec_contents[i]];
                [self.detailArray addObject:model];
            }
            self.fareInfo = responseObject[@"data"][@"fare_info"];
            self.titleLabel.text = responseObject[@"data"][@"goods_name"];
            self.priceLable.text = responseObject[@"data"][@"price_coupon"];
            self.stockLabel.text = [NSString stringWithFormat:@"库存%@件",responseObject[@"data"][@"goods_inventory"]];
            [self.scoreBtn setTitle:[NSString stringWithFormat:@"赠送积分%@",responseObject[@"data"][@"gift_integration_scale"]] forState:(UIControlStateNormal)];
            NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:responseObject[@"data"][@"price"] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),NSFontAttributeName:FontSize(14),NSForegroundColorAttributeName:TextLessImportColor}];
            self.pastPriceLabel.attributedText = string;
            self.fareMoney = [NSString stringWithFormat:@"运费:%@",responseObject[@"data"][@"fare_info"][@"fare_name"]];
            self.commentCountString = [NSString stringWithFormat:@"商品评价(%ld)",[responseObject[@"data"][@"comment"] [@"comment_count"] integerValue]];
            self.comentCount = [responseObject [@"data"][@"comment"][@"comment_count"] integerValue];
            self.picturesArray = [NSArray arrayWithArray:responseObject[@"data"][@"pictures"]];
            self.header.imageURLStringsGroup = self.picturesArray;
            for (int i = 0 ; i < [responseObject [@"data"][@"comment"][@"comment_content"] count]; i ++) {
                CommentModel * model = [[CommentModel alloc]init];
                [model setValuesForKeysWithDictionary:responseObject[@"data"][@"comment"][@"comment_content"][i]];
                [self.commentsArray addObject:model];
            }
            [self.tableview reloadData];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.tableview animated:YES];
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2) {
        CommentModel * model  = self.commentsArray[indexPath.row];
        if (model.pictures.count > 0) {
            return 130 - 16 + model.textHeight + 100;
        }
        return 130 - 16 + model.textHeight;
    }else if (indexPath.section == 3)
    {
        return kScreenHeight - 100;
    }
    return 50;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if (section == 1)
    {
        return 2;
    }else if (section == 3)
    {
        return 1;
    }
    else
    {
        return self.commentsArray.count >= 2 ? 2 : self.commentsArray.count;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
        view.backgroundColor = [UIColor whiteColor];
        UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(view.centerX - 50, 10, 100, 30)];
        [view addSubview:btn];
        btn.titleLabel.font = FontSize(14);
        [btn setTitleColor:TextAssistColor forState:(UIControlStateNormal)];
        if (self.comentCount == 0) {
            [btn setTitle:@"暂无评论" forState:(UIControlStateNormal)];
        }else
        {
            [btn setTitle:@"查看更多评论" forState:(UIControlStateNormal)];
            [btn addTarget:self action:@selector(toCommentVC) forControlEvents:(UIControlEventTouchUpInside)];
        }
        return view;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        return 50;
    }
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 10, kScreenWidth, 60)];
        view.backgroundColor = [UIColor clearColor];
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, kScreenWidth, 50)];
        label.font = FontSize(13);
        label.textColor = TextLessImportColor;
        label.text = [NSString stringWithFormat:@"     %@",self.commentCountString];
        label.backgroundColor = [UIColor whiteColor];
        [view addSubview:label];
        
        return view;
    }
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }else if (section == 2)
    {
        return 60;
    }
    else
    {
        return 5;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {  // 运费说明
            self.productionView = [[[NSBundle mainBundle] loadNibNamed:@"ProductionView" owner:self options:nil] lastObject];
            self.productionView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight / 2);
            self.productionView.titleLabel.text = @"运费说明";
            [self.productionView configureTextViewWithDict:self.fareInfo];
            self.productionView.scoreBtn.hidden = YES;
            self.productionView.scoreLabel.hidden = YES;
            self.productionView.rebackBtn.hidden = YES;
            self.productionView.rebackLabel.hidden = YES;
            self.zh_popupController = [zhPopupController new];
            self.zh_popupController.layoutType = zhPopupLayoutTypeBottom;
            [self.zh_popupController presentContentView:self.productionView duration:0.2 springAnimated:NO];
            __weak typeof (self) weakSelf = self;
            self.productionView.removeBlock = ^{
                [weakSelf.zh_popupController dismiss];
            };
            
        }else if (indexPath.row == 1){
            // 选择规格
            [self chooiseGoods];
        }
    }else if (indexPath.section == 2){
        
    }else if (indexPath.section == 0 )
    {
        self.productionView = [[[NSBundle mainBundle] loadNibNamed:@"ProductionView" owner:self options:nil] lastObject];
        self.productionView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight / 2);
        self.productionView.textView.hidden = YES;
        self.productionView.titleLabel.text = @"服务说明";
        self.zh_popupController = [zhPopupController new];
        self.zh_popupController.layoutType = zhPopupLayoutTypeBottom;
        [self.zh_popupController presentContentView:self.productionView duration:0.2 springAnimated:NO];
        __weak typeof (self) weakSelf = self;
        self.productionView.removeBlock = ^{
            [weakSelf.zh_popupController dismiss];
        };
    }
}
#pragma mark 规格
-(void)chooiseGoods
{
    __weak typeof (self) weakSelf = self;
    self.specView.modelArray = self.modelArray;
    self.specView.detailArray = self.detailArray;
    self.specView.takeInCartBlock = ^(DetailGoodsModel *model, NSString *num) {
        NSMutableDictionary * dict = [NSMutableDictionary dictionary];
        if (model.goods_spec_id) {
            dict = @{@"token":self.userToken,@"goods_id":weakSelf.goodsID,@"goods_spec_id":model.goods_spec_id,@"goods_number":num}.mutableCopy;
        }else if (self.specDeep > 0 && model.goods_spec_id.length == 0) {
            [MBProgressHUD showError:@"请选择商品规格" toView:weakSelf.specView];
            return ;
        }
        else
        {
            dict = @{@"token":self.userToken,@"goods_id":weakSelf.goodsID,@"goods_number":num}.mutableCopy;
        }
        [MBProgressHUD showHUDAddedTo:weakSelf.specView animated:YES];
        [HTTPTool POSTForm:[NSString stringWithFormat:@"%@cart/add-to-cart",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
            [MBProgressHUD hideHUDForView:weakSelf.specView animated:YES];
            if (isSuccess) {
                [weakSelf.zh_popupController dismiss];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"reload" object:nil];
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:weakSelf.specView animated:YES];
        }];
    };
    
    self.specView.buyNowBlock = ^(NSString *specID, NSString *num) {
        NSMutableDictionary * dict = @{@"token":weakSelf.userToken,@"goods_id":weakSelf.goodsID}.mutableCopy;
        if (self.specDeep > 0 && specID.length == 0) {
            [MBProgressHUD showError:@"请选择商品规格" toView:weakSelf.specView];
            return ;
        }
        if (specID) {
            [dict setObject:specID forKey:@"goods_spec_id"];
        }
        [dict setObject:num forKey:@"goods_number"];
        [MBProgressHUD showHUDAddedTo:weakSelf.specView animated:YES];
        [HTTPTool POSTForm:[NSString stringWithFormat:@"%@order/pre-confer-order",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
            [MBProgressHUD hideHUDForView:weakSelf.specView animated:YES];
            if (isSuccess) {
                [weakSelf.zh_popupController dismiss];
                AddressModel * addressModel = [AddressModel new];
                [addressModel setValuesForKeysWithDictionary:responseObject[@"data"][@"address"]];
                NSMutableArray * array = [NSMutableArray array];
                for (int i = 0; i < [responseObject[@"data"][@"order_detail"] count]; i ++) {
                    OrderDetailModel * model = [OrderDetailModel new];
                    [model setValuesForKeysWithDictionary:responseObject[@"data"][@"order_detail"][i]];
                    [array addObject:model];
                }
                ConfirmOrderController * vc = [[ConfirmOrderController alloc]init];
                vc.addressModel = addressModel;
                vc.reKey = responseObject[@"data"][@"order_info_redis_key"];
                vc.orderArray = array;
                vc.goodsSum = responseObject[@"data"][@"goods_sum"];
                vc.totalMoney = responseObject[@"data"][@"total_price_format"];
                vc.farePrice = responseObject[@"data"][@"fare_price_format"];
                
                vc.addressCouponKey = responseObject[@"data"][@"goods_redis_key"];
                if ([responseObject[@"data"][@"coupon"] count] > 0) {
                    OrderTicketModel * model = [[OrderTicketModel alloc]init];
                    [model setValuesForKeysWithDictionary:responseObject[@"data"][@"coupon"]];
                    vc.ticketModel = model;
                }
                BaseNavigationController * VC = [[BaseNavigationController alloc]initWithRootViewController:vc];
                [weakSelf.navigationController presentViewController:VC animated:YES completion:nil];
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:weakSelf.specView animated:YES];
        }];
        
    };
    
    
    self.specView.closeBlock = ^{
        [weakSelf.zh_popupController dismiss];
    };
    
    self.zh_popupController = [zhPopupController new];
    self.zh_popupController.layoutType = zhPopupLayoutTypeBottom;
    [self.zh_popupController presentContentView:self.specView duration:0.2 springAnimated:NO];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tableview) {
        switch (indexPath.section) {
            case 0:
            {
                UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BtnCell" forIndexPath:indexPath];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                [cell.contentView addSubview:self.scoreBtn];
                [self.scoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.offset(10);
                    make.centerY.equalTo(cell.contentView);
                    make.size.mas_equalTo(CGSizeMake(100, 20));
                }];
                
                [cell.contentView addSubview:self.rebackBtn];
                [self.rebackBtn setTitle:@"7天退换" forState:(UIControlStateNormal)];
                [self.rebackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.scoreBtn.mas_right).offset(10);
                    make.centerY.equalTo(self.scoreBtn);
                    make.size.mas_offset(CGSizeMake(100, 20));
                }];
                return cell;
            }
                break;
            case 1:
            {
                UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BtnCell" forIndexPath:indexPath];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                cell.textLabel.font = FontSize(13);
                cell.textLabel.textColor = TextLessImportColor;
                if (indexPath.row == 0) {
                    cell.textLabel.text = self.fareMoney;
                }else if(indexPath.row == 1)
                {
                    cell.textLabel.text = @"请选择规格";
                }
                return cell;
            }
                break;
            case 2:
            {
                CommentModel * model  = self.commentsArray[indexPath.row];
                CommentsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CommentsCell" forIndexPath:indexPath];
                [cell bindDataWithModel:model];
                return cell;
            }
                break;
                
            case 3:
            {
                UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"webCell" forIndexPath:indexPath];
                return cell;
            }
                break;
            default:
                break;
        }
    }
    return nil;
}

- (void)toCommentVC
{
    GoodsCommentController * vc = [[GoodsCommentController alloc]init];
    vc.goodsID = self.goodsID;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)shareAction:(UIButton *)sender
{
    NSLog(@"分享");
}

- (void)moreAction:(UIButton *)sender
{
    NSLog(@"更多");
}

-(SpecificationView *)specView
{
    if (!_specView) {
        _specView = [[[NSBundle mainBundle] loadNibNamed:@"SpecificationView" owner:self options:nil] lastObject];
        _specView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    }
    return _specView;
}

-(UIView *)headerView
{
    if (!_headerView) {
        _headerView = [[UIView alloc]init];
        _headerView.backgroundColor = [UIColor whiteColor];
    }
    return _headerView;
}

-(UIButton *)scoreBtn
{
    if (!_scoreBtn) {
        _scoreBtn = [[UIButton alloc]init];
        [_scoreBtn setImage:Image(@"icon_积分_小") forState:(UIControlStateNormal)];
        [_scoreBtn setTitleColor:TextAssistColor forState:(UIControlStateNormal)];
        _scoreBtn.titleLabel.font = FontSize(13);
        _scoreBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    }
    return _scoreBtn;
}

-(UIButton *)rebackBtn
{
    if (!_rebackBtn) {
        _rebackBtn = [[UIButton alloc]init];
        [_rebackBtn setImage:Image(@"icon_7天退换") forState:(UIControlStateNormal)];
        [_rebackBtn setTitleColor:TextAssistColor forState:(UIControlStateNormal)];
        _rebackBtn.titleLabel.font = FontSize(13);
        _rebackBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    }
    return _rebackBtn;
}

-(NSMutableArray *)commentsArray
{
    if (!_commentsArray) {
        _commentsArray = [NSMutableArray array];
    }
    return _commentsArray;
}

-(BottomTool *)tool
{
    if (!_tool) {
        _tool = [[[NSBundle mainBundle] loadNibNamed:@"BottomTool" owner:self options:nil] firstObject];
        _tool.backgroundColor = [UIColor whiteColor];
    }
    return _tool;
}

-(GoodsModel *)dataModel
{
    if (!_dataModel) {
        _dataModel = [GoodsModel new];
    }
    return _dataModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
